package org.jeecg.modules.rooms.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.entity.BusMarketMealCouponsUsed;
import org.jeecg.modules.business.enums.CouponsStatusEnum;
import org.jeecg.modules.business.mapper.BusMarketMealCouponsUsedMapper;
import org.jeecg.modules.rooms.entity.CesRoomLayoutPriceDate;
import org.jeecg.modules.rooms.mapper.CesRoomLayoutPriceDateMapper;
import org.jeecg.modules.rooms.service.ICesRoomLayoutPriceDateService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description: ces_room_layout_price_date
 * @Author: jeecg-boot
 * @Date:   2023-03-23
 * @Version: V1.0
 */
@Service
public class CesRoomLayoutPriceDateServiceImpl extends ServiceImpl<CesRoomLayoutPriceDateMapper, CesRoomLayoutPriceDate> implements ICesRoomLayoutPriceDateService {

    @Resource
    private CesRoomLayoutPriceDateMapper cesRoomLayoutPriceDateMapper;

    /**
     * 房价列表
     * @param page
     * @param hotelIds
     * @param startDate
     * @param endDate
     * @return
     */
    public Page<HashMap<String,Object>> pageList(Page<HashMap<String,Object>> page, @Param("hotelIds") ArrayList<String> hotelIds, Date startDate, Date endDate) {
        ArrayList<String> dates = new ArrayList<String>();
        long getTime = endDate.getTime() - startDate.getTime();
        long day = getTime / (1000 * 60 * 60 * 24);
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar=new GregorianCalendar();
        for (Integer i=0;i<=day;i++) {
            calendar.setTime(startDate);
            calendar.add(Calendar.DATE, i);
            String dateString = formatter.format(calendar.getTime());
            dates.add(dateString);
        }
        return page.setRecords(cesRoomLayoutPriceDateMapper.pageList(page, dates, hotelIds));
    }
}
